package cn.stronglink.asset.message.mq.dam.entity.dacai;

import java.io.UnsupportedEncodingException;

import cn.stronglink.asset.message.mq.dam.entity.ScreenCommandEntity;
import cn.stronglink.suite.core.util.ByteUtil;

public class UpdateTextCommandFactory extends DacaiDefaultCommandFactory {
	protected final static String COMMAND_CODE = "B110";
	protected final static String CHANGE_SCREEN_CODE = "B100";
	/**
	 * 需要更新的场景Id和文本控件Id
	 */
	protected short screenId, textId;
	/**
	 * 更新的内容
	 */
	protected String content;
	/**
	 * 所在机柜
	 */
	protected String rackConverCode;

	/**
	 * 更新文本控件的命令工厂
	 * 
	 * @param rackConverCode
	 * @param screenId
	 * @param textId
	 * @param content
	 */
	public UpdateTextCommandFactory(String rackConverCode, short screenId, short textId, String content) {
		this.rackConverCode = rackConverCode;
		this.screenId = screenId;
		this.textId = textId;
		this.content = content;
	}

	@Override
	public ScreenCommandEntity createScreenCommand() throws UnsupportedEncodingException {
		StringBuffer sb = new StringBuffer(COMMAND_HEADER);
		sb.append(COMMAND_CODE);
		sb.append(ByteUtil.byteArrToHexString(ByteUtil.shortToByteArr(this.screenId))); // 界面id
		sb.append(ByteUtil.byteArrToHexString(ByteUtil.shortToByteArr(this.textId))); // 控件id
		sb.append(ByteUtil.byteArrToHexString(this.content.getBytes("GBK"))); // 控件内容
		sb.append(COMMAND_FOOTER);

		ScreenCommandEntity sc = new ScreenCommandEntity();
		sc.setCommand(sb.toString());
		sc.setRackConverCode(this.rackConverCode);

		sb.setLength(0);
		sb = null;
		
		return sc;
	}

	@Override
	public ScreenCommandEntity changeScreenCommand() throws Exception {
		StringBuffer sb = new StringBuffer(COMMAND_HEADER);
		sb.append(CHANGE_SCREEN_CODE);
		sb.append(COMMAND_FOOTER);

		ScreenCommandEntity sc = new ScreenCommandEntity();
		sc.setCommand(sb.toString());
		sc.setRackConverCode(this.rackConverCode);

		sb.setLength(0);
		sb = null;
		
		return sc;
	}
}
